package com.briup.exception;

import com.briup.util.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 将web层中所有的处理器方法的异常进行统一处理
 */
@ControllerAdvice
public class TestExceptionhandler {
    public TestExceptionhandler(){
        System.out.println("创建TestExceptionhandler对象");
    }

    //     String
    //     void
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e){
        System.out.println("全局的异常处理");
        return new Result(10001,e.getMessage());
    }
}
